﻿using System.Windows.Input;
using Omnia.DataModels;
using Omnia.Library;
using System.Windows;
using Omnia.Library.Extensions;

namespace Omnia.ViewModels
{
    public class CaseAddViewModel : CaseViewModel
    {
        #region Properties
        private CaseInfo caseItemToAdd = new CaseInfo();
        public CaseInfo CaseItemToAdd
        {
            get { return caseItemToAdd; }
            set
            {
                caseItemToAdd = value;
                RaisePropertyChanged(() => CaseItemToAdd);
            }
        }
        #endregion

        #region Method
        public void Insert(CaseInfo entity)
        {
            Database.CollectionOfCases.InsertOnSubmit(entity);
            Save();

            RaisePropertyChanged(() => CasesCollection);
            CaseItemToAdd = new CaseInfo();
            RaisePropertyChanged(() => CaseItemToAdd);
        }
        #endregion

        #region Commands
        public ICommand AddCaseCommand
        {
            get
            {
                return new GenericCommand()
                {
                    ExecuteCallback = delegate
                    {
                        Insert(CaseItemToAdd);
                        //MessageBox.Show(Application.Current.FindResource<string>(ResourceKeys.IDS_NOTE_CASE_ADD_OK), Application.Current.FindResource<string>(ResourceKeys.IDS_NOTE_CASE_ADD_TITLE), MessageBoxButton.OK);
                        NavigateBack();
                    }
                };
            }
        }
        #endregion
    }
}
